﻿var zombies = zombies || {};

zombies.Profile = function () {
    var self = this;

    self.Loaded = ko.observable(false);

    self.Avatar = ko.observable("../Advertise/DefaultAssets/NoAvatar.gif");
    self.FullName = ko.observable();
    self.Gender = ko.observable();
    self.Birthday = ko.observable();
    self.CMND = ko.observable();
    self.Email = ko.observable();
    self.Address = ko.observable();
    self.Phone = ko.observable();
    self.Point = ko.observable();
    self.Level = ko.observable();
};

var load = function () {
    $.ajax({
        type: "GET",
        url: "/api/MemberProfile/GetUserProfile",
        contentType: "application/json",
        dataType: 'json'
    }).done(function (item) {
        if (item.Avatar != null && item.Avatar != '') {
            profileViewModel.Avatar(item.Avatar);
        }
        profileViewModel.FullName(item.FirstName + ' ' + item.LastName);
        profileViewModel.Gender(item.Gender=='Male'?'Nam':'Nữ');
        profileViewModel.Birthday(moment(item.Birthday).format('LLL'));
        profileViewModel.CMND(item.CMND);
        profileViewModel.Email(item.Email);
        profileViewModel.Address(item.Address);
        profileViewModel.Phone(item.Phone);
        profileViewModel.Point(item.Point);
        profileViewModel.Level(item.Level);
        profileViewModel.Loaded(true);
    });
};

var profileViewModel;
$(document).ready(function () {
    profileViewModel = new zombies.Profile();
    load();
    ko.applyBindings(profileViewModel, document.getElementById("my-container"));
});